home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload Trio 2 / Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO / dir42 / gnudbm14.zip / README < prev    next >
Text File  |  1990-08-14  |  14KB  |  390 lines

  1. This is release 1.4 of GNU dbm.  Better documentation will be written
  2. soon.  For now, this file briefly describes the contents of this
  3. release and how to use it.
  4.  
  5. The files are:
  6.  
  7. COPYING        - Copying information.
  8. README        - This file.
  9.  
  10. bucket.c, extern.h, falloc.c, findkey.c, gdbm.proto, gdbmclose.c,
  11. gdbmdefs.h, gdbmdelete.c, gdbmerrno.h, gdbmfetch.c, gdbmopen.c,
  12. gdbmreorg.c, gdbmseq.c, gdbmstore.c, global.c, gndbm.h, hash.c
  13. systems.h, update.c, version.c - Source for GNU dbm library.
  14.  
  15. dbminit.c, delete.c, fetch.c, seq.c, store.c - Source for the DBM interface.
  16.  
  17. dbmclose.c, dbmdelete.c, dbmdirfno.c, dbmfetch.c, dbmopen.c, dbmpagfno.c
  18. dbmseq.c, dbmstore.c, ndbm.h - Source for the NDBM interface.
  19.  
  20. Makefile     - Makefile, will make gdbm.a  (BSD and SYSV)
  21. testgdbm.c    - A simple test program.
  22. testdbm.c    - A simple test program.
  23. testndbm.c    - A simple test program.
  24. conv2gdbm.c    - A dbm database conversion program.
  25.  
  26. CHANGES from 1.0 to 1.4:
  27.   1.  Mainly bug fixes.
  28.   2.  A define for "dbmclose()" was added to dbm.h for those few 
  29.       implementaions that need that call.
  30.   3.  For details, see the ChangeLog.
  31.  
  32. CHANGES from 0.9 to 1.0:
  33.   1.  Makefiles were combined into one and a few new things added to it.
  34.   2.  Several minor bugs were fixed including a cache bug.
  35.   3.  Two new calls (dbm_pagfno, dbm_dirfno) were added to the NDBM interface.
  36.   3.  A conversion program from dbm files to gdbm files was added.
  37.   4.  Reorganize was changed to allow complex file names. (dir/file form)
  38.   5.  testgdbm, testndbm, and testdbm were modified to return key and data
  39.       pairs where needed and to take an optional file name as an argument.
  40.       testgdbm had some command characters changed.
  41.   6.  The DBM and NDBM interfaces were separated.
  42.   7.  An include file for dbm users was added. (dbm.h)
  43.   8.  The include file for ndbm users was renamed ndbm.h. (It was gndbm.h.)
  44.  
  45. CHANGES from 0.8 to 0.9:
  46.   1.  The hash function changed.
  47.   2.  The file format changed.
  48.   3.  There was a complete rewrite of falloc.c.
  49.   4.  There were added compatiblity routines for ndbm.
  50.   5.  The file names for dbm compatibility routines were made to
  51.       look like dbm.
  52.   6.  Test programs changed.
  53.   7.  Support for System V.
  54.   8.  Various other small changes.
  55.   9.  The need for recovery and associated code was removed.
  56.  
  57.  
  58. GNU dbm is a set of database routines that use extendible hashing and
  59. works similar to the standard UNIX dbm routines.  The basic unit of
  60. data is the structure
  61.  
  62.   typedef struct {
  63.              char *dptr;
  64.              int   dsize;
  65.           } datum;
  66.  
  67. The following is a quick list of the routines.  After this list, a
  68. longer description of each routine will be given.  An include file
  69. will be produced that can be included by the user. The file is
  70. "gdbm.h".  The following routines are defined in terms of gdbm.h:
  71.  
  72.   GDBM_FILE gdbm_open ( name, block_size, read_write, mode, fatal_func )
  73.  
  74.   void gdbm_close ( dbf )
  75.   
  76.   int gdbm_store ( dbf, key, content, flags )
  77.  
  78.   datum gdbm_fetch ( dbf, key )
  79.  
  80.   int gdbm_delete ( dbf, key )
  81.  
  82.   datum gdbm_firstkey ( dbf )
  83.  
  84.   datum gdbm_nextkey ( dbf, key )
  85.  
  86.   int gdbm_reorganize ( dbf )
  87.  
  88.  
  89. For compatibility with the standard dbm, the following routines are 
  90. defined.  There is an include file for dbm users called "dbm.h".
  91.  
  92.   int dbminit ( name )
  93.  
  94.   int store ( key, content )
  95.  
  96.   datum fetch ( key )
  97.  
  98.   int delete ( key )
  99.  
  100.   datum firstkey ()
  101.  
  102.   datum nextkey ( key )
  103.  
  104.  
  105. There are also compatibility routines for ndbm.  For ndbm compatiblity
  106. routines, you need the include file "ndbm.h".  The routines are:
  107.  
  108. DBM *dbm_open (name, flags, mode)
  109.  
  110. void dbm_close (file)
  111.  
  112. datum dbm_fetch (file, key)
  113.  
  114. int dbm_store (file, key, content, flags)
  115.  
  116. int dbm_delete (file, key)
  117.  
  118. datum dbm_firstkey (file)
  119.  
  120. datum dbm_nextkey (file)
  121.  
  122. int dbm_error (file)
  123.  
  124. int dbm_clearerr (file)
  125.  
  126. int dbm_pagfno (file)
  127.  
  128. int dbm_dirfno (file)
  129.  
  130.  
  131. Description of GNU dbm routines.
  132. --------------------------------
  133.  
  134. GNU dbm allows multiple data files.  A routine that opens a gdbm file
  135. is designated as a "reader" or a "writer".  Only one writer may open a
  136. gdbm file and many readers may open the file.  Readers and writers can
  137. not open the gdbm file at the same time. The procedure for opening a
  138. gdbm file is:
  139.  
  140. GDBM_FILE dbf;
  141.  
  142. dbf = gdbm_open ( name, block_size, read_write, mode, fatal_func )
  143.  
  144. The parameters are:
  145.   char *name - the name of the file (the complete name, gdbm does
  146.       not append any characters to this name)
  147.   int block_size - the size of a single transfer from disk to memory.
  148.       This parameter is ignored unless the file is a new file.
  149.       The minimum size is 512.  If it is less than 512, dbm will
  150.       use the stat block size for the file system.
  151.   int read_write - 0 => reader, 1 => writer, 2 => writer (if the database
  152.       does not exist, create a new one, 3 => writer and create a new
  153.       database regardless if one exists.  (Defined in gdbm.h as
  154.       GDBM_READER, GDBM_WRITER, GDBM_WRCREAT, GDBM_NEWDB.)
  155.   int mode - file mode (see chmod(2) and open(2)) if the file is created.
  156.   void (*fatal_func) () - a function for dbm to call if it detects a
  157.       fatal error. The only parameter of this function is a string.
  158.       If the value of 0 is provided, gdbm will use a default function.
  159.  
  160. The return value, dbf, is the pointer needed by all other routines to
  161. access that gdbm file.  If the return is the NULL pointer, gdbm_open
  162. was not successful.  The errors can be found in "gdbm_errno" for gdbm
  163. errors and in "errno" for file system errors.  (For error codes, see
  164. gdbmerrno.h.)
  165.  
  166. In all of the following calls, the parameter "dbf" refers to the pointer
  167. returned from gdbm_open.
  168.  
  169. It is important that every file opened is also closed.  This is needed to
  170. update the reader/writer count on the file.  This is done by:
  171.  
  172.   gdbm_close(dbf);
  173.  
  174.  
  175. The database is used by 3 primary routines.  The first stores data in the
  176. database.
  177.  
  178.   ret = gdbm_store ( dbf, key, content, flag )
  179.  
  180.   The parameters are:
  181.      char *dbf - the pointer returned by gdbm_open
  182.      datum key - the key data
  183.      datum content - the data to be associated with the key
  184.      int   flag - 0 => insert only, generate an error if key exists.
  185.               1 => replace contents if key exists.  (Defined in
  186.               gdbm.h as GDBM_INSERT and GDBM_REPLACE.)
  187.  
  188.   If a reader calls store, ret gets -1.  If called with GDBM_INSERT and
  189.   key is in the database, ret gets 1.  Otherwise, ret is 0.
  190.   NOTICE: If you store data for a key that is already in the data base,
  191.   gdbm replaces the old data with the new data if called with GDBM_REPLACE.
  192.   You do not get two data items for the same key and you do not get an
  193.   error from gdbm_store.
  194.   NOTICE: The size in gdbm is not restricted like dbm or ndbm.  Your data
  195.   can be as large as your "want".
  196.  
  197. To search for some data:
  198.  
  199.   content = gdbm_fetch ( dbf, key )
  200.  
  201.   The parameters are:
  202.      char *dbf - the pointer returned by gdbm_open
  203.      datum key - the key data
  204.  
  205.   The "datum" returned in content is a pointer to the data found.  If the
  206.   dptr is NULL, no data was found.  If dptr is not NULL, then it points
  207.   to data allocated by malloc.  gdbm does not automatically free this data.
  208.   The user must free this storage when done using it.  This eliminates the
  209.   need to copy the result to save it for later use. (You just save the 
  210.   pointer.)
  211.  
  212. To remove some data from the database:
  213.  
  214.   ret = gdbm_delete ( dbf, key )
  215.  
  216.   The parameters are:
  217.      char *dbf - the pointer returned by gdbm_open
  218.      datum key - the key data
  219.  
  220.   The ret value is -1 if the item is not present or the requester is a reader.
  221.   The ret value is 0 if there was a successful delete.
  222.  
  223.  
  224. The next two routines allow for accessing all items in the database.  This 
  225. access is not key sequential, but it is guaranteed to visit every key in
  226. the database once.  (The order has to do with the hash values.)
  227.  
  228.   key = gdbm_firstkey ( dbf )
  229.  
  230.   nextkey = gdbm_nextkey ( dbf, key )
  231.  
  232.   The parameters are:
  233.      char *dbf - the pointer returned by gdbm_open
  234.      datum key - the key data
  235.  
  236.   The return values are both datum.  If key.dptr or nextkey.dptr is NULL,
  237.   there is no first key or next key.  Again notice that dptr points to
  238.   data allocated by malloc and gdbm will not free it for you. 
  239.  
  240. The following routine should be used very seldom.  
  241.   
  242.   ret = gdbm_reorganize ( dbf )
  243.  
  244.   If you have had a lot of deletions and would like to shrink the space
  245.   used by the gdbm file, the this routine will reorganize the database.
  246.   gdbm will not shorten the length of a gdbm file except by using this
  247.   reorganization.  (Deleted file space will be reused.)
  248.  
  249.  
  250. The following two are variables that may need to be used:
  251.  
  252.   gdbm_error gdbm_errno   -   the variable that contains more information
  253.                               about gdbm errors.  ( gdbm.h has the
  254.                   definitions of the error values. )
  255.  
  256.   char * gdbm_version     -   the string containing the version information.
  257.  
  258.  
  259. There are a few more things of interest.  First, gdbm files are not
  260. "sparse".  You can copy them with the UNIX cp command and they will
  261. not expand in the copying process.  Also, there is a compatibility
  262. mode for use with programs that already use UNIX dbm.  In this
  263. compatibility mode, no gdbm file pointer is required by the user.
  264. Only one file may be opened at a time.  All users in compatibility
  265. mode are assumed to be writers.  If the gdbm file is a read only, it
  266. will fail as a writer, but will also try to open it as a reader.  All
  267. returned pointers in datum structures point to data that gdbm WILL
  268. free.  They should be treated as static pointers (as standard UNIX dbm
  269. does).  The compatibility routine names are the same as the UNIX dbm
  270. routine names.  Their definitions follow:
  271.  
  272.   int dbminit ( name )
  273.  
  274.   int store ( key, content )
  275.  
  276.   datum fetch ( key )
  277.  
  278.   int delete ( key )
  279.  
  280.   datum firstkey ()
  281.  
  282.   datum nextkey ( key )
  283.  
  284. NOTE: Some implementations have an include file "dbm.h".  That file is just
  285. a file that defines datum and the above routines.  Many original dbm 
  286. sites do not have a "dbm.h" file.  One is included here for those who 
  287. want it.
  288.  
  289. WARNING: standard UNIX dbm and GNU dbm do not have the same data format in the
  290. file.  You cannot access a standard UNIX dbm file with GNU dbm!  If you want
  291. to use an old database with GNU dbm, you must use the convert program.
  292.  
  293. Also, GNU dbm has compatibility routines for ndbm.  For ndbm compatiblity
  294. routines, you need the include file "ndbm.h".  
  295.  
  296. WARNING: If you have ndbm and gdbm, there is a conflict in the names of the
  297. include file for the ndbm interface and the original ndbm package.  Do not
  298. blindly copy "ndbm.h" to your include directory.
  299.  
  300. The routines are:
  301.  
  302.     DBM *dbm_open (name, flags, mode)
  303.  
  304.     void dbm_close (file)
  305.  
  306.     datum dbm_fetch (file, key)
  307.  
  308.     int dbm_store (file, key, content, flags)
  309.  
  310.     int dbm_delete (file, key)
  311.  
  312.     datum dbm_firstkey (file)
  313.  
  314.     datum dbm_nextkey (file)
  315.  
  316.     int dbm_error (file)
  317.  
  318.     int dbm_clearerr (file)
  319.  
  320.     int dbm_dirfno (file)
  321.  
  322.     int dbm_pagfno (file)
  323.  
  324. Again, just like ndbm, any returned datum can be assumed to be static
  325. storage.  You do not have to free that memory, the ndbm compatibility
  326. routines will do it for you.
  327.  
  328.  
  329. Notes on making GNU dbm.
  330. ------------------------
  331.  
  332. The "Makefile" will make both "gdbm.a", the collection of gdbm routines and
  333. three simple test programs that uses the gdbm routines.  Two test programs
  334. test the dbm and the ndbm interface routines.  The third was use to help
  335. debug gdbm and contains "inside knowledge."   The first two can be linked
  336. using the original dbm and ndbm routines.  The makefile also makes the
  337. conversion program, conv2gdbm.   The make commands are:
  338.  
  339.    make gdbm.a        makes the gdbm.a archive.
  340.    make testgdbm    makes both gdbm.a and the gdbm test program.
  341.    make testdbm     makes both gdbm.a and the dbm test program with gdbm.
  342.    make testndbm    makes both gdbm.a and the ndbm test program with gdbm.
  343.    make allgdbm        makes all of the above.
  344.    make tdbm        makes the dbm test program linked with dbm, not gdbm.
  345.    make tndbm        makes the ndbm test program linked with ndbm, not gdbm.
  346.    make alldbm        makes the two previous programs.
  347.    make conv2gdbm    makes the conversion program.
  348.    make all        makes all the above.
  349.    make install        installs gdbm.a as /usr/lib/libgdbm.a and gdbm.h.
  350.  
  351.  
  352. CONV2GDBM
  353. ---------
  354.  
  355. The program conv2gdbm has been provided to help you convert from dbm
  356. databases to gdbm.  The usage is:
  357.  
  358.    conv2gdbm [-q] [-b block_size] dbm_file [gdbm_file]
  359.  
  360. The optional "block_size" is the same as in gdbm_open.  The dbm_file is
  361. the name of the dbm file without the .pag or .dir extensions.  The
  362. optional gdbm_file is the complete file name.  If not included, the
  363. gdbm file name is the same as the dbm file name without any extensions.
  364. That is "conv2gdbm dbmfile" converts the files "dbmfile.pag" and
  365. "dbmfile.dir" into a gdbm file called "dbmfile".  The -q option causes
  366. conv2gdbm to work quietly.
  367.  
  368.  
  369. System V support  (And other systems.)
  370. --------------------------------------
  371.  
  372. There is now support for System V.  This done via the systems.h file.
  373. This is the place where all system dependencies should go.  The 
  374. makefile should make gdbm with a few changes.  The makefile describes
  375. the changes necessary for use with System V.  Also, read the makefile
  376. and edit it if you use gcc.  There are several places where changes
  377. are needed to use gcc.
  378.   1)  uncomment: #CC=gcc
  379.   2)  change the lines to make the test programs. (See the comments.)
  380.  
  381. If you port gdbm to another system, try to follow the change style used for
  382. System V changes.  Please send your changes to phil@cs.wwu.edu if you would
  383. like your changes included in a future release of gdbm.
  384.  
  385. Please send bug reports to bug-gnu-utils@prep.ai.mit.edu.
  386.  
  387. Thank you.
  388.  
  389.  
  390.